package com.aclever.resouces;

import javax.swing.*;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * Это модель таблицы, то бишь, один из важнейших и активных компонентов
 */

public class SiteTableModel implements TableModel {
    private SiteDB siteDB;
    public JButton parseOne = null;
    public JButton moreInfo = null;




    public SiteTableModel(SiteDB dbase){
        this.siteDB = dbase;





        parseOne = new JButton("Parse Site");
        moreInfo = new JButton("More Info");



    }

    @Override
    public int getRowCount() {
        return siteDB.getRowSize();
    }

    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public String getColumnName(int columnIndex) {
        switch (columnIndex){
            case 0:
                return "№";
            case 1:
                return "Site Name";
            case 2:
                return "Request Message";
            case 3:
                return "Request Code";
            case 4:
                return "";
            case 5:
                return "";

            }
        return "";
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if(columnIndex == 1){
            return String.class;
        }else{
            return new TableColumn(1).getClass();

        }


    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        if(columnIndex == 1){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {


              Sitebean sitebean =   siteDB.getSites().get(rowIndex);
            switch (columnIndex){
                case 0:
                    return rowIndex + 1;
                case 1:
                    return sitebean.getSiteHost();
                case 2:
                    return sitebean.getSiteResponseMessage();
                case 3:
                    return sitebean.getSiteResponseCode();
                case 4:
                    return parseOne;
                case 5:
                    return moreInfo;



            }


        return "";

    }








    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        String addedVal = (String) aValue;
        System.out.println(addedVal);


    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
        //To change body of implemented methods use File | Settings | File Templates.
    }


}
